/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mvp.levelup.swing2;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 *
 * @author WORKSPOT2
 */
public class ActionTestFrame extends JFrame
{

    public ActionTestFrame()
    {
        ActionTestPanel ap = new ActionTestPanel();
        add(ap);
        setSize(200, 200);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    class ActionTestPanel extends JPanel
    {

        private JLabel label;

        public ActionTestPanel()
        {
            addText();
            addButtons();
        }

        private void addText()
        {
            setLayout(new BorderLayout());
            label = new JLabel("<html><h1>BOLD TEXT!</h1></html>");
            add(label, BorderLayout.CENTER);
            JOptionPane.showMessageDialog(null, "Mess", "Mess", ERROR, null);
        }

        private void addButtons()
        {
            JPanel buttonPanel = new JPanel();
            JButton redButton = new JButton("Red");
            ColorChangeAction colorChangeAction = new ColorChangeAction(label);
            redButton.addActionListener(colorChangeAction);
            JButton greenButton = new JButton("Green");
            greenButton.addActionListener(colorChangeAction);
            buttonPanel.add(redButton);
            buttonPanel.add(greenButton);
            add(buttonPanel, BorderLayout.SOUTH);
        }
    }

    class ColorChangeAction implements ActionListener
    {
        private JLabel textLabel;

        public ColorChangeAction(JLabel label)
        {
            this.textLabel = label;
        }
        
        
        @Override
        public void actionPerformed(ActionEvent e)
        {
            JButton pressedButton = (JButton) e.getSource();
            String label = pressedButton.getText();
            if (label.equalsIgnoreCase("red"))
            {
                textLabel.setForeground(Color.red);
            }
            else if (label.equalsIgnoreCase("green"))
            {
                textLabel.setForeground(Color.green);
            }
        }
    }
}
